/*
 * @Author: your name
 * @Date: 2022-11-25 13:28:06
 * @LastEditTime: 2022-11-25 13:30:55
 * @LastEditors: DESKTOP-4QFD9PO
 * @Description: In User Settings Edit
 * @FilePath: \ClothMes\src\utils\TreeUtils.ts
 */
class TreeUtils  {
    private valueField: string
   
    private childrenField:string
    constructor(valueField:string = '',childrenField:string = ''){
        this.valueField = valueField || 'value'
        this.childrenField = childrenField || 'children'
     
    }

    findTreeNodeById = (treeData:any[],id:string | number,callback:Function) => {
        const _this = this
        treeData.forEach((o:any)=>{
            if(o[this.valueField] === id){
                callback(o)
                return false
            } else {
                if(Array.isArray(o[_this.childrenField]) && o[_this.childrenField].length > 0){
                    _this.findTreeNodeById(o[_this.childrenField],id,callback)
                } 
            }
        })
    }
    
 }

 export default TreeUtils